package cn.itcast.service;

import cn.itcast.mapper.UserMapper;
import cn.itcast.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Random;

/**
 * @Author: taft
 * @Date: 2018-9-23 12:21
 */
@Service
public class UserService {
    @Autowired
    private UserMapper userMapper;

    public User queryUserById(Long id) {
        // 为了演示超时现象，我们在这里然线程休眠,时间随机 0~2000毫秒
        try {
            int sleepTime = new Random().nextInt(2000);
            System.out.println("本次服务提供者查询id："+id+" 耗时："+sleepTime);
            Thread.sleep(sleepTime);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        User user = userMapper.selectByPrimaryKey(id);
        System.out.println("user = " + user);
        return user;
    }
}
